package com.haoting.mamba.player.controller;

import com.haoting.mamba.player.entity.PlayerAdvancedEntity;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Stream;

public class StreamTest {

    public static void main(String[] args) {
        int[] a = new int[]{8,2,3,5,1};
//        Arrays.stream(maopao(a)).forEach(System.out::println);
//        Arrays.stream(xuanze(a)).forEach(System.out::println);
        Arrays.stream(charu(a)).forEach(System.out::println);
    }

    //冒泡排序
    public static int[] maopao(int[] a){
        for (int i = 0;i<a.length-1;i++){
            for (int j=0;j<a.length-1-i;j++){
                if(a[j]>a[j+1]){
                    int temp = a[j];
                    a[j]=a[j+1];
                    a[j+1] = temp;
                }
            }
        }
        return a;
    }
    //选择排序
    public static int[] xuanze(int[] a){
        for(int i = 0;i<a.length-1;i++){
            int min = i;
            for(int j = i+1;j<a.length;j++){
                if(a[j]<a[min]){
                    min = j;
                }
            }
            int temp = a[i];
            a[i]=a[min];
            a[min] = temp;
        }
        return a;
    }
    //插入排序
    public static int[] charu(int[] a){
        for(int i = 1;i<a.length;i++){
            for(int j =i;j>0;j--){
                if(a[j]<a[j-1]){
                    int temp = a[j];
                    a[j]= a[j-1];
                    a[j-1] = temp;
                }
            }
        }

        return a;
    }
}
